package leetcode;


/**
 * 最大连续1的个数
 */
public class LeetCode485 {
    public int findMaxConsecutiveOnes(int[] nums) {
        int i = -1, j = 0, max = 0;
        while (j < nums.length) {
            if (nums[j] == 1) {
                if (i == -1) i = j;
            } else {
                if (i != -1 && max < j - i) max = j - i;
                i = -1;
            }
            j++;
        }
        if (i != -1 && max < j - i) max = j - i;
        return max;
    }

    public static void main(String[] args) {
        LeetCode485 leetCode485 = new LeetCode485();
        System.out.println(leetCode485.findMaxConsecutiveOnes(new int[]{1, 1, 0, 1}));;
    }
}